/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.uefs.cedoc.db;

import br.uefs.cedoc.db.exception.DBConnectionException;

/**
 *
 * @author Gregory Porto
 */

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


/**
 * Classe responsavel por fornecer o metodo de retornar o maximo campo da tabela de nome passado
 * @author SMAU
 *
 */
public class DBOperacoes {
	
	public int getMaxID(String nomeColuna, String nomeTabela) throws DBConnectionException, SQLException{
		String comandoSQL = "SELECT MAX("+ nomeColuna+") FROM "+ nomeTabela;

		Connection conn = DBController.getInstance().getConnection();
		Statement statement = conn.createStatement();

		ResultSet rs = statement.executeQuery(comandoSQL);
		if (rs.next()) {
			return rs.getInt(1);
		}
		statement.close();
		return -1;

	}
	

}

